package com.shuiyun.log.controller;

import com.shuiyun.log.anno.LogAnno;
import com.shuiyun.log.enums.LogType;
import com.shuiyun.log.service.DemoService;
import com.shuiyun.log.service.UserService;
import com.shuiyun.log.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: LogDemo
 * @description: 测试日志
 * @author: gujun
 * @create: 2019-10-10 13:51
 **/
@RestController
@RequestMapping("/log")
@Slf4j
public class LogController {
    @Autowired
    private UserService userService;
    @Autowired
    private DemoService demoService;

    @PostMapping
    @LogAnno(dataType = "user",logType = LogType.INSERT)
    public UserVO insert(@RequestBody UserVO userVO){
        log.info("新增用户："+userVO.getUserName());
        return userVO;
    }

    @PutMapping
    public UserVO update(@RequestBody UserVO userVO){
        log.info("更新用户："+userVO.getUserName());
//        userService.editUser(userVO);
        return userVO;
    }

    @DeleteMapping
    @LogAnno(dataType = "user",logType = LogType.DELETE)
    public String delete(int id){
        log.info("删除用户："+id);
        return "删除成功";
    }

    @PostMapping("/test")
    public String test(){
        demoService.test();
        return "ok";
    }

}
